/**
 * Created by Administrator on 2018/5/8.
 */
define(function (require,exports,module) {
    require("./enter.css");
    var sTpl = require("./template.html");
    var VueComponent = Vue.extend({
        props: ['parentData'],
        template: sTpl,
        methods: {
            pickerMakeDate:function (val) {
              this.formInline.makeDate = val;
            },
            saveFlightInfo:function () {
                var $this = this;
                props:['parentData'],
                this.$refs.formInline.validate(function (validate) {
                    if(validate){
                        axios.post(basepath+"/api/flightInfo/saveFlightInfo",$this.formInline).then(function (response) {
                            $this.$notify({
                                title: '保存成功',
                                message: '保存成功'
                            });

                            if($this.parentData.showOrEdit!='edit'){
                                $this.$refs.formInline.resetFields();
                            }
                            if($this.parentData.dataCallbak){
                                $this.parentData.dataCallbak(response.data);
                            }
                        })
                    }else{
                        $this.$notify({
                            title: '保存失败',
                            message: '请检查飞行器信息是否完整'
                        });

                    }
                })
            },
            initInlineForm:function () {
              return {
                  "flightKind":null,
                  "flightType":null,
                  "flightNum":null,
                  "engineNumber":null,
                  "length":null,
                  "hight":null,
                  "wingspan":null,
                  engingPower:"",
                  fuelType:"",
                  cylinderNumber:"",
                  numberOfBlades:"",
                  makeDate:"",
                  manufacturingNo:"",
                  "cabinSpaceLength":null,
                  "cabinSpaceHeight":null,
                  "cabinSpaceWidth":null,
                  "emptyWeight":null,
                  "maximumTakeOffWeight":null,
                  "maximumAvailableLoad":null,
                  "maximumTankCapacity":null,
                  "maximumCruiseSpeed":null,
                  "maximumRange":null,
                  "maximumSlipBeforeWeight":null,
                  "maximumLandingWeight":null,
                  "maximumZeroFuelWeight":null,
                  "maximumFlyingHeight":null,
                  "maximumClimbingSpeedOfSeaLevel":null,
                  "theTimeOfNavigationAtTheBestSpeed":null,
                  "maximumFlyingSpeed":null,
                  "bearingWeightOfInnerSilo":null,
                  "innerBinVolume":null,
                  "outerBinVolume":null,
                  "outerBinWeight":null,
                  "takeoffRunwayLength":null,
                  "remoteCruiseSpeed":null,
                  "highSpeedCruiseSpeed":null,
                  "flankRatio":null,
                  "wingArea":null,
                  "mainWheelbase":null,
                  "frontMainWheelbase":null,
                  "groundSpacingOfTheFuselage":null,
                  "maximumBusinessLoad":null,
                  "maximumFlatSpeed":null,
                  "cruisingSpeed":null,
                  "practicalLift":null,
                  "landingSkatingDistance":null,
                  "takeoffDistance":null,
                  "propellerDiameter":null,
                  "centerDistanceOfPropeller":null,
                  "singleRiseAndDownLine":null,
                  "loadNumber":null
              }
            },
            selectFlightType:function (val) {
                var flightType=this.flightTypeInfos.find(function (data) {

                        return data.flightType==val;

                })
                for(var a in flightType){
                  this.formInline[a] = flightType[a];
                }
              console.log(flightType);
            },
            queryFlightInfo:function (filter) {
                $.ajaxSettings.async=false;
                var result=$.get("/dam/api/flightInfo/queryFlightInfo?filter="+filter);
                $.ajaxSettings.async=true;
                return result;
            },
            returnParent:function () {
                this.parentData.returnCallbak();
            }
        },
        data:function () {
            var $this = this;

            var checkNum = function(rule, value, callback) {
                if(value===''||value===null||value==undefined){
                    return callback();

                }
                if (typeof value !=="number") {
                    return callback(new Error('必须为数字类型'));
                }
                return  callback();
            };
            var checkUniqueFlightNum=function (rule, value, callback) {
                if(!value){
                    return  callback(new Error('值不能为空'));
                }
                if(value&&value.length>30){
                    return  callback(new Error('字符长度不能超过30'));
                }
                var data=$this.queryFlightInfo(value);
                data.responseJSON.forEach(function (data) {
                    if(data.flightNum==value&&data.flightId!=$this.formInline.flightId){
                        return   callback(new Error("航班号必须为唯一值"));
                    }
                });
                return callback();
            }
            var checkStr =function(rule, value, callback){
                if(value&&value.length>30){
                    return   callback(new Error('字符长度不能超过30'));
                }
                return callback();
            }
            var checkStrReq =function(rule, value, callback){
                if(!value){
                    return  callback(new Error('值不能为空'));
                }
                if(value&&value.length>30){
                    return  callback(new Error('字符长度不能超过30'));
                }
                    return callback();
            }
            return {
                flightTypeInfoPo:{},
                activeNames:["1","2","3"],
                flightTypeInfos:[],
                formInline:this.initInlineForm()
                ,formInlineRule:{
                "flightKind":[{ validator: checkStrReq, trigger: 'blur' }],
                    "flightType":[{ validator: checkStrReq, trigger: 'blur' }],
                    "flightNum":[{ validator: checkUniqueFlightNum, trigger: 'blur' }],
                    "engineNumber":[{ validator: checkStr, trigger: 'blur' }],
                    "length":[{ validator: checkNum, trigger: 'blur' }],
                    "hight":[{ validator: checkNum, trigger: 'blur' }],
                    "wingspan":[{ validator: checkNum, trigger: 'blur' }],
                    "cabinSpaceLength":[{ validator: checkNum, trigger: 'blur' }],
                    "cabinSpaceHeight":[{ validator: checkNum, trigger: 'blur' }],
                    "cabinSpaceWidth":[{ validator: checkNum, trigger: 'blur' }],
                    "emptyWeight":[{ validator: checkNum, trigger: 'blur' }],
                    engingPower:[{ validator: checkStr, trigger: 'blur' }],
                    fuelType:[{ validator: checkStr, trigger: 'blur' }],
                    cylinderNumber:[{ validator: checkStr, trigger: 'blur' }],
                    numberOfBlades:[{ validator: checkStr, trigger: 'blur' }],
                    makeDate:[{ validator: checkStr, trigger: 'blur' }],
                    manufacturingNo:[{ validator: checkStr, trigger: 'blur' }],
                    "maximumTakeOffWeight":[{ validator: checkNum, trigger: 'blur' }],
                    "maximumAvailableLoad":[{ validator: checkNum, trigger: 'blur' }],
                    "maximumTankCapacity":[{ validator: checkNum, trigger: 'blur' }],
                    "maximumCruiseSpeed":[{ validator: checkNum, trigger: 'blur' }],
                    "maximumRange":[{ validator: checkNum, trigger: 'blur' }],
                    "maximumSlipBeforeWeight":[{ validator: checkNum, trigger: 'blur' }],
                    "maximumLandingWeight":[{ validator: checkNum, trigger: 'blur' }],
                    "maximumZeroFuelWeight":[{ validator: checkNum, trigger: 'blur' }],
                    "maximumFlyingHeight":[{ validator: checkNum, trigger: 'blur' }],
                    "maximumClimbingSpeedOfSeaLevel":[{ validator: checkNum, trigger: 'blur' }],
                    "theTimeOfNavigationAtTheBestSpeed":[{ validator: checkNum, trigger: 'blur' }],
                    "maximumFlyingSpeed":[{ validator: checkNum, trigger: 'blur' }],
                    "bearingWeightOfInnerSilo":[{ validator: checkNum, trigger: 'blur' }],
                    "innerBinVolume":[{ validator: checkNum, trigger: 'blur' }],
                    "outerBinVolume":[{ validator: checkNum, trigger: 'blur' }],
                    "outerBinWeight":[{ validator: checkNum, trigger: 'blur' }],
                    "takeoffRunwayLength":[{ validator: checkNum, trigger: 'blur' }],
                    "remoteCruiseSpeed":[{ validator: checkNum, trigger: 'blur' }],
                    "highSpeedCruiseSpeed":[{ validator: checkNum, trigger: 'blur' }],
                    "flankRatio":[{ validator: checkNum, trigger: 'blur' }],
                    "wingArea":[{ validator: checkNum, trigger: 'blur' }],
                    "mainWheelbase":[{ validator: checkNum, trigger: 'blur' }],
                    "frontMainWheelbase":[{ validator: checkNum, trigger: 'blur' }],
                    "groundSpacingOfTheFuselage":[{ validator: checkNum, trigger: 'blur' }],
                    "maximumBusinessLoad":[{ validator: checkNum, trigger: 'blur' }],
                    "maximumFlatSpeed":[{ validator: checkNum, trigger: 'blur' }],
                    "cruisingSpeed":[{ validator: checkNum, trigger: 'blur' }],
                    "practicalLift":[{ validator: checkNum, trigger: 'blur' }],
                    "landingSkatingDistance":[{ validator: checkNum, trigger: 'blur' }],
                    "takeoffDistance":[{ validator: checkNum, trigger: 'blur' }],
                    "propellerDiameter":[{ validator: checkNum, trigger: 'blur' }],
                    "centerDistanceOfPropeller":[{ validator: checkNum, trigger: 'blur' }],
                    "singleRiseAndDownLine":[{ validator: checkStr, trigger: 'blur' }],
                    "loadNumber":[{ validator: checkNum, trigger: 'blur' }]
            }
            };
        },
        created:function (){
            var $this = this;
            axios.get("/dam/api/flightTypeInfo/queryFlightTypeInfo").then(function (response) {
                $this.flightTypeInfos=response.data;
                console.log($this.flightTypeInfos);
            })

        },
        activated:function () {
            messages.$emit('change','航空器基础信息录入');
        }
    });

    return VueComponent;
});